﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Basic4Net.BusinessRules;
using Basic4Net.OAWeb.Base;

namespace Basic4Net.OAWeb.Module_Finance
{
    public partial class FinanceHistory : BasePage
    {
        private static Amount _amount;
        protected static Amount HAmount
        {
            get { return _amount ?? (_amount = new Amount()); }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;

            BindYears();
            DrYearChanged(Repeater1 as object, new EventArgs());
        }

        protected void DrYearChanged(object sender, EventArgs e)
        {
            int year = 0;
            Int32.TryParse(drYear.SelectedValue, out year);
            if (year < 1)
                return;
            IList<object> res = HAmount.GetAmountsInYear(year, SchoolMark);
            Repeater1.DataSource = res;
            Repeater1.DataBind();
        }

        private void BindYears()
        {
            IList<int> yearList = HAmount.GetYears(SchoolMark);
            if (yearList == null || yearList.Count < 1)
            {
                drYear.Items.Add(new ListItem("--当前没有拨款历史数据--", "-1"));
                return;
            }

            drYear.DataSource = yearList;
            drYear.DataBind();
        }
    }
}